/**
 * Created by WYH on 17/4/19.
 */
angular.module('tribalc').service('LockModel', ['Enum', 'TimeFormat', function (Enum, TimeFormat) {

    var LockModel = function (object) {
        var self = this;

        init();

        function init() {
            if (object) {
                self.id = object.id;
                self.managerId = object.managerId;
                self.name = object.name;
                self.desc = object.desc;
                self.activityTime = object.activityTime;
                self.actived = object.actived;
                self.authType = object.authType;
                self.managerName = object.managerName;
                self.controlId = object.controlId;
                self.controlKey = object.controlKey;
                self.guestEnabled = object.guestEnabled;
                self.snr = object.snr;
            } else {
                self.activityTime = [null, null];
            }
            self.manager = null;

        }
    };

    LockModel.prototype.getAllObject = function () {
        return {
            id: this.id,
            managerId: this.managerId,
            managerName: this.managerName,
            name: this.name,
            desc: this.desc,
            activityTime: this.activityTime,
            actived: this.actived,
            authType: this.authType,
            controlId: this.controlId,
            controlKey: this.controlKey,
            snr: this.snr,
        }
    };

    LockModel.prototype.getObject = function () {
        return {
            managerId: this.managerId,
            managerName: this.managerName,
            name: this.name,
            desc: this.desc,
            activityTime: this.activityTime,
            actived: this.actived,
            authType: this.authType,
            controlId: this.controlId,
            controlKey: this.controlKey,
            snr: this.snr,
        }
    };

    LockModel.prototype.getActivedStr = function () {
        return this.actived ? '可用' : '不可用';
    };


    LockModel.prototype.getAuthTypeStr = function () {
        if (!this.authType) return false;
        return {
            'PRIVATE':'私有授权',
            'GENERIC':'通用授权',
            'EXCLUSIVE':'专有授权'
        }[this.authType];
    };
    
    LockModel.prototype.getStartTimeStr = function () {

        if (!this.activityTime || this.activityTime.length != 2 || this.activityTime[0] == null) {
            return null;
        }
        var beginTime = this.activityTime[0];
        return TimeFormat.changeSecondToStr(beginTime);
    };
    
    LockModel.prototype.getEndTimeStr = function () {
        if (!this.activityTime || this.activityTime.length != 2 || this.activityTime[1] == null) {
            return null;
        }

        var endTime = this.activityTime[1];
        return TimeFormat.changeSecondToStr(endTime);
    };
    
    LockModel.prototype.setupStartTime = function (timeStr) {
        this.activityTime[0] = TimeFormat.changeHourTimeStrToInt(timeStr);
    };

    LockModel.prototype.setupEndTime = function (timeStr) {
        this.activityTime[1] = TimeFormat.changeHourTimeStrToInt(timeStr);
    };

    LockModel.setupLocks = function (array) {
        var staffList = [];
        array.forEach(function (value) {
            var staff = new LockModel(value);
            staffList.push(staff);
        });
        return staffList;
    };


    return LockModel;


}]);